import { trigger, track, effect } from './reactive-computed.js'

function computed (getter) {
  let value
  let dirty = true
  const effectFn = effect(getter, {
    lazy: true,
    scheduler () {
      if(!dirty){
        dirty = true
        trigger(obj,"value")
      }
    }
  })

  return (obj = {
    value () {
      if (dirty) {
        value = effectFn()
        dirty = false
      }
      track(obj,"value")
      return value
    }
  })
}
